<?php
session_start();
require_once("../lib/DbWrapper.class.php");
require("../libs/Smarty.class.php");
require("../libs/myUtil.class.php");

$smarty =new Smarty;

//input.phpから来たかどうかを判断する処理
if($_SESSION["comment_edit_confirm_id"] != $_POST["comment_edit_confirm_id"]){
    header("Location:http://localhost/bbs/admin/index.php");
}else{
    //同じページでの更新を防ぐ処理
    $_SESSION["comment_edit_confirm_id"] = rand();
}

$id = $_POST["id"];
$nickname =$_POST["nickname"];
$content =$_POST["content"];
$category_id = $_POST["category_id"];
$url = $_POST["url"];

DbWrapper::dbChoice();

//クエリを送信する
$sql = "UPDATE comment SET nickname = \"".
        $nickname.
        "\", content = \"".
        $content.
        "\", category_id = \"".
        $category_id.
        "\", url = \"".
        $url.
        "\" WHERE id =".
        $id;

$result = mysql_query($sql);

if ($_SESSION["tmpphoto"] !="") {
    $tmpphoto =$_SESSION["tmpphoto"];
    $photoname =$id.myUtil::getFileExt($tmpphoto);
    copy($tmpphoto, "../img/".$photoname);
    $sql = "UPDATE comment SET photo =\"".
           $photoname.
           "\" where id = ".
           $id;
    $result = mysql_query($sql);
}
print_r($_SESSION);
$smarty->display("comment_edit_result.tpl");
?>